# -*- coding: utf-8 -*-

import subprocess, threading, time
from AutoIt import AutoIt


def optionsEnregistrement(destination, adresseVlc):
    liste = [adresseVlc]
    concat = "dshow:// :dshow-vdev= :dshow-adev= :dshow-caching=200 :sout=#transcode{vcodec=h264,vb=0,scale=0.5,acodec=none}:file{dst=" + destination + "} :no-sout-rtp-sap :no-sout-standard-sap :ttl=1 :sout-keep"
    liste += concat.split(" ")
    return liste
        
def optionsLecture(nomFichier, adresseVlc="C:\\Program Files (x86)\\VideoLAN\\VLC\\vlc.exe"):
    return [adresseVlc, nomFichier]

class VlcInstance(threading.Thread):
    def __init__(self, arguments):
        self.stdout = None
        self.stderr = None
        threading.Thread.__init__(self)
        self._stopevent = threading.Event()
        self.ai = AutoIt().autoit
        self.arguments = arguments
        
    
    def run(self):
        self.process = subprocess.Popen(self.arguments, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
        self.stdout, self.stderr = self.process.communicate()
        
    def stop(self):
        self._stopevent.set()
        
        


if __name__=="__main__":        
    vlc = VlcInstance(optionsEnregistrement("D:\\workspace\\Synchronisation\\data\\testounet.avi"))
    #vlc = VlcInstance(optionsLecture("D:\\workspace\\Synchronisation\\data\\testounet.avi"))
    vlc.start()
